//RunDB
import java.sql.*;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

//import com.mysql.jdbc.Connection;
//import com.mysql.jdbc.Statement;


public class IF {

	   static Connection connection;
	   Statement statement;

	   public static void loadDriver() throws ClassNotFoundException{
	      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	   }

	   public void makeConnection() throws SQLException {
	      connection=
	         DriverManager.getConnection("jdbc:odbc:student");
	   }

	   public void buildStatement() throws SQLException {
	      statement = connection.createStatement();
	   }

	   public void executeQuery() throws SQLException {

	      boolean foundResults =
	         statement.execute("SELECT * FROM Students");
	      if(foundResults){
	         ResultSet set = statement.getResultSet();
	         if(set!=null) displayResults(set);
	      }else {
	         connection.close();
	      }
	   }

	   static void displayResults(ResultSet rs) throws SQLException {
	      ResultSetMetaData metaData = rs.getMetaData();
	      int columns=metaData.getColumnCount();
	      String text="";

	      while(rs.next()){
	         for(int i=1;i<=columns;++i) {
	            text+="<"+metaData.getColumnName(i)+">";
	            text+=rs.getString(i);
	             text+="</"+metaData.getColumnName(i)+">";
	             text+="n";
	         }
	         text+="n";
	      }

	      System.out.println(text);

	   }



	   
	   
		/**
		 * @param args
		 * @throws ClassNotFoundException 
		 * @throws SQLException 
		 */
		public static void main(String[] args) throws ClassNotFoundException, SQLException {
			// TODO Auto-generated method stub
//version 1			
//			loadDriver();
//			makeConnection();
//			buildStatement();
//			executeQuery();
			
			//Version 2
			   CustomerDAO dao = new CustomerDAO();

			   Document doc    = dao.getCustomerList(connection);
			   System.out.println(JDBCUtil.serialize(doc));
		
		}

}
